﻿using System;
using System.Linq;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HtmlAgilityPack;

namespace Workshop
{
    [TestClass]
    public class urls_tests
    {

        private static readonly HtmlWeb _web = new HtmlWeb();
        private static HtmlDocument _doc = null;

        private HtmlDocument LoadUrl(string url)
        {
            HtmlDocument result = null;
            bool pass;
            int i = 0;
            do
            {
                try
                {
                    result = _web.Load(url);
                    pass = true;
                }
                catch (WebException)
                {
                    i++;
                    if (i > 10) throw new Exception();
                    pass = false;
                }
            } while (!pass);

            return result;
        }


        [TestMethod]
        public void try_urls()
        {
            _doc = LoadUrl("http://www.nfl.com/schedules/2000/REG6");
            var result = _doc.DocumentNode.Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value == "list-matchup-row-team");
        }
    }
}
